#ifndef DATA_MODEL_H
#define DATA_MODEL_H

#include <QAbstractListModel>
#include <QVariant>
#include <QMap>
#include <QList>
#include <QObject>
#include <QTreeView>
#include <QAbstractTableModel>
#include <QItemSelectionModel>

#include "TreeItem.h"
#include "clientLogic.h"

class Server;

class DataModel: public QAbstractItemModel
{
	Q_OBJECT

public:
	DataModel(QMap<int,QList<ClientLogic*>*> *data, QObject *parent=0);
	~DataModel();
	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                         int role = Qt::DisplayRole) const;
	QModelIndex index(int row, int column, const QModelIndex &parent) const;
    QModelIndex parent(const QModelIndex &index) const;
	void setupModelData();
	bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex());
    bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex());
	Qt::ItemFlags flags(const QModelIndex &index) const;

	void emitChanged(int start,int end);
	void emitReset();

private:
	QItemSelectionModel *selectionModelTV;
	QMap<int,ClientLogic*> *client_list;
	QMap<int,QList<ClientLogic*>*> *group_list;
	TreeItem *rootItem;
	
};


class ApplicationTableModel: public QAbstractTableModel
{
	Q_OBJECT

public:
	ApplicationTableModel(QMap<int, ClientLogic*> *data,
	QMap<int,QList<ClientLogic*>*> *datag, QTreeView *clientsTree, Server *s, QObject *parent=0);
	Qt::ItemFlags ApplicationTableModel::flags(const QModelIndex &index) const;
	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount (const QModelIndex &parent = QModelIndex()) const;
	QVariant data (const QModelIndex &index, int role) const;
	QVariant headerData(int section, Qt::Orientation orientation, int role) const;
	QModelIndex MycreateIndex(int row, int column, void *data = 0);
	void setRemoteAppList(QList<RemoteApplication*> &rApps) const;
	void emitReset();
	void emitDataChanged();
private:
	// base dati dalla quale attingere
	QMap<int,ClientLogic*> *client_list;
	QMap<int,QList<ClientLogic*>*> *group_list;
	QItemSelectionModel *selectionModel;
	static const QStringList statusStrings;
	//Mi serve anche la reference alla list view per capire gli oggetti selezionati
	Server *_serverRef;
};

#endif
